import React from "react";
import $ from "jquery"
import "./navTop.css"

class NavTop extends React.Component{
    constructor(props){
        super(props)
        this.state={
            username:JSON.parse(window.localStorage.getItem("userInfo")).username||""
        }
    }
    loginOut(){
        console.log(111)
        $.ajax({
            url:"/user/logout.do",
            type:"post"
        })
        window.localStorage.removeItem("userInfo")
        window.location.hash="#/login"
        
    }
    render(){
        return(
            <div className="navbar navbar-default top-navbar">
            <div className="navbar-header">
               
                <a className="navbar-brand" href="index.html"><b>In</b>sight</a>
            </div>

            <ul className="nav navbar-top-links navbar-right">
         
                
               
                
               
               
                <li className="dropdown">
                    <a className="dropdown-toggle"  href="#">
                        <i className="fa fa-user fa-fw"></i><span>欢迎{this.state.username}</span> <i className="fa fa-caret-down"></i>
                    </a>
                    <ul className="dropdown-menu dropdown-user">
                        
                        
                        <li><a className="_loginOut" onClick={this.loginOut.bind(this)}><i className="fa fa-sign-out fa-fw"></i> 退出登录</a>
                        </li>
                    </ul>
                    
                </li>
                
            </ul>
        </div>
        )
    }
}
export default NavTop